//
//  PhotoRecord.h
//  XPhoto
//
//  Created by baboy on 2019/6/19.
//  Copyright © 2019 baboy. All rights reserved.
//

#import "Model.h"
#import "PhotoAsset.h"
#import "User.h"
#import "PostSerial.h"
#import "PostItem.h"
#import "SearchArgs.h"

NS_ASSUME_NONNULL_BEGIN

#define API_POST_CREATE                 @"post_add"
#define API_POST_SEARCH                 @"post_search"
#define API_POST_SEARCH_BY_TAG          @"post_search_by_tag"
#define API_POST_SEARCH_BY_TOPIC        @"post_search_by_topic"
#define API_POST_SEARCH_BY_SERIAL       @"post_search_by_serial"
#define API_POST_SEARCH_BY_SERIAL_TAG   @"post_search_by_serial_tag"


#define RECORD_TYPE_PHOTO @"photo"
#define RECORD_TYPE_VIDEO @"video"


@class PostSearchArgs;

@interface Post : Model
@property(nonatomic, assign) NSInteger id;
@property(nonatomic, assign) NSInteger uid;
@property(nonatomic, strong) User *user;
@property(nonatomic, assign) NSInteger serialId;
@property(nonatomic, strong) PostSerial *serial;
@property(nonatomic, strong) NSArray *serialIds;
@property(nonatomic, strong) NSArray<PostSerial*> *serials;
@property(nonatomic, strong) PostSerial *serialsItem;
@property(nonatomic, strong) NSString *type;
@property(nonatomic, strong) NSString *content;
@property(nonatomic, strong) NSString *addr;
@property(nonatomic, strong) NSString *coverUrl;
@property(nonatomic, strong) NSString *coverThumb;
@property(nonatomic, assign) NSInteger width;
@property(nonatomic, assign) NSInteger height;
@property(nonatomic, strong) NSString *lat;
@property(nonatomic, strong) NSString *lng;
@property(nonatomic, strong) NSArray *tags;
@property(nonatomic, strong) NSMutableArray<PostItem*> *items;
@property(nonatomic, strong) PostItem *itemsItem;
@property(nonatomic, assign) NSInteger itemCount;
@property(nonatomic, assign) NSInteger viewCount;
@property(nonatomic, assign) NSInteger likeCount;
@property(nonatomic, assign) NSInteger shareCount;
@property(nonatomic, assign) NSInteger commentCount;
@property(nonatomic, assign) NSInteger policy;
@property(nonatomic, strong) NSDate *createTime;
@property(nonatomic, strong) NSDate *updateTime;

+ (id)searchWithArgs:(PostSearchArgs *)args
            callback:(void(^)(id task, id response, NSError *error))callback;


+ (id)searchByTagWithArgs:(PostSearchArgs *)args
                 callback:(void(^)(id task, id response, NSError *error))callback;

+ (id)searchByTopicWithArgs:(PostSearchArgs *)args
                   callback:(void(^)(id task, id response, NSError *error))callback;

+ (id)searchBySerialWithArgs:(PostSearchArgs *)args
                   callback:(void(^)(id task, id response, NSError *error))callback;

+ (id)searchBySerialTagWithArgs:(PostSearchArgs *)args
                   callback:(void(^)(id task, id response, NSError *error))callback;

+ (id)create:(Post*)record
      photos:(NSArray*)photos
photoUploadProgress:(void(^)(NSString *key, float p))progress
  completion:(void(^)(void))callback;
+ (NSMutableArray *)locationSerialGroup:(NSMutableArray*)groupArray withPhotoRecords:(NSArray<Post*>*)photoRecords;
+ (NSMutableArray *)dateSerialGroup:(NSMutableArray*)groupArray withPhotoRecords:(NSArray<Post*>*)photoRecords;
+ (NSMutableArray *)tagSerialGroup:(NSMutableArray*)groupArray withPhotoRecords:(NSArray<Post*>*)photoRecords;
@end

@interface PostSearchArgs : SearchArgs
@property(nonatomic, strong) NSNumber *uid;
@property(nonatomic, strong) NSNumber *followerUid;
@property(nonatomic, strong) NSNumber *serialId;
@property(nonatomic, strong) NSString *topic;
@property(nonatomic, strong) NSString *tag;
@end

@interface PostLoc : Model
@property(nonatomic, assign) NSInteger id;
@property(nonatomic, strong) NSString *lng;
@property(nonatomic, strong) NSString *lat;
@property(nonatomic, strong) NSString *addr;

@property(nonatomic, assign) NSInteger postCount;
@property(nonatomic, assign) NSInteger userCount;
@property(nonatomic, assign) NSInteger createUid;
@property(nonatomic, strong) NSDate *createTime;
@property(nonatomic, strong) NSDate *updateTime;
@end


@interface PostTopic : Model
@property(nonatomic, assign) NSInteger id;
@property(nonatomic, strong) NSString *title;
@property(nonatomic, assign) NSInteger postCount;
@property(nonatomic, assign) NSInteger userCount;
@property(nonatomic, assign) NSInteger createUid;
@property(nonatomic, strong) NSDate *createTime;
@property(nonatomic, strong) NSDate *updateTime;
@end

NS_ASSUME_NONNULL_END
